<?php
class eBayGetUser extends gravy{
	public $username="";
	public $token="";
	public $user="";
	public $xml="";

	function __construct($username="", $token=""){
		parent::__construct();
		$this->username=$username;
		$this->token=$token;
	}

	public function get(){
		$result=false;

		if(strlen($this->username)>0 && strlen($this->token)>0){
			$requestXml='<?xml version="1.0" encoding="utf-8"?>';
			$requestXml.='<GetUserRequest xmlns="urn:ebay:apis:eBLBaseComponents">';
			$requestXml.='	<RequesterCredentials>';
			$requestXml.='		<eBayAuthToken>'.$this->token.'</eBayAuthToken> ';
			$requestXml.='	</RequesterCredentials>';
			$requestXml.='	<DetailLevel>ReturnAll</DetailLevel>';
			$requestXml.='	<UserID>'.$this->username.'</UserID>';
			$requestXml.='</GetUserRequest>';

			$req=new eBayRequest("GetUser");
			if($this->xml=$req->fetch($requestXml)){
				//Add user data to array, then return it.
				$name=(string)$this->xml->User->RegistrationAddress->Name;
				$result=$this->user=array(
					"userName"=>$this->username,
					"firstName"=>substr($name,0,strpos($name," ")),
					"lastName"=>substr($name,strpos($name," ")+1),
					"eias"=>(string)$this->xml->User->EIASToken,
					"email"=>(string)$this->xml->User->Email
				);
			}
		}
		return($result);
	}
}
?>